package com.eis.thirdsys.connector.conf.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.eis.thirdsys.connector.conf.ConnectorConfig;
import com.eis.thirdsys.connector.conf.bean.ConfParameter;
import com.eis.thirdsys.connector.conf.bean.ConfParameterName;

public abstract class GeneralConnectorConfig implements ConnectorConfig {
	/**
	 * Set 
	 * 
	 */
    private Map<String, ConfParameterName> parameterNames = new HashMap<String, ConfParameterName>();
    
    private Map<String, ConfParameter> confParameters = new HashMap<String, ConfParameter>();
    
    public GeneralConnectorConfig() {
    	super();
    	setup();
    }
    /**
     * Set up the parameterNames Map
     */
    protected abstract void setup();
    
    protected void addConfParameterName(ConfParameterName name) {
    	parameterNames.put(name.getIdName(), name);
    }

	public List<ConfParameter> getConfParameters() {
		return new ArrayList<ConfParameter>(confParameters.values());
	}

	public boolean setOneConf(String idName, String value) {
		// check if the idName belongs to this config
		if (parameterNames.get(idName) != null) {
			confParameters.put(idName, new ConfParameter(parameterNames.get(idName), value));
			return true;
		}
		
		return false;
	}

	public ConfParameter getOneConf(String idName) {
		return confParameters.get(idName);
	}
}
